玩學機的基礎繪圖指令,就是利用C語言編寫底層繪圖功能函數,再打包成可被 micropython 使用者直接呼叫使用的函式庫,讓開發者可以專注在開發應用介面。
常用的內建函數有:
wb.cls(wb.PINK)
wb.cls()
wb.box(60, 64, 20, 20, wb.RED)
wb.cls()
W = 160
H = 128
Counter = 0
while Counter < 100:
x1 = wb.rand(W)
y1 = wb.rand(H)
x2 = wb.rand(W)
y2 = wb.rand(H)
color = wb.rand(65536)
width = wb.rand(1, 3)
wb.line(x1, y1, x2, y2, color, width)
Counter = Counter + 1
wb.box(0, 100, 160, 20, wb.BLACK)
wb.str("Plot "+ str(Counter) +" lines!", 5, 110, 2, 2)
wb.cls()
wb.blitpal()
wb.blitbuf()
wb.blitimg(272, 30, 40, 16, 16)
wb.blitimg(336, 80, 40, 16, 16)
wb.blitimg(340, 100, 40, 16, 16)
wb.blitimg(344, 120, 40, 16, 16)
wb.blitimg(348, 140, 40, 16, 16)
wb.blitstr("ITHome Ironman 2024", 4, 70)
wb.blitstr("DDLab Inc.", 30, 100)
wb.blit()
Micropython 要顯示圖檔需要注意幾個地方,請按照下面的步驟處理您的圖片:
import time
wb.cls()
images = ["/img/西沙罐頭圖案.bin", "/img/柯基.bin", "/img/比熊.bin", "/img/白色雪納瑞.bin"]
current_image = 0
while True:
if wb.getkey() == 1:
current_image = (current_image + 1) % len(images)
f = open(images[current_image], "rb")
data = bytearray(f.read())
wb.showbuf(data)
f.close()
del data
time.sleep(0.5)